home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
oper_sys
/
weyl
/
weyl_lsp.lha
/
rational-numbers.lisp
< prev
next >
Wrap
Text File
|
1991-10-24
|
2KB
|
61 lines
;;; -*- Mode:Lisp; Package:Weyli; Base:10; Lowercase:T; Syntax:Common-Lisp -*-
;;; ===========================================================================
;;; Rational Numbers
;;; ===========================================================================
;;; (c) Copyright 1989, 1991 Cornell University
;;; $Id: rational-numbers.lisp,v 2.6 1991/10/24 19:27:40 rz Exp $
(in-package "WEYLI")
(define-domain-element-classes rational-numbers
rational-number)
(defmethod print-object ((d rational-numbers) stream)
#+Genera
(format stream "~'bQ~")
#-Genera
(princ "Q" stream))
(define-domain-creator rational-numbers ()
(make-instance 'rational-numbers)
:predicate (lambda (d) (eql (class-name (class-of d)) 'rational-numbers)))
(define-domain-creator quotient-field ((ring rational-integers))
(make-rational-numbers))
(defmethod get-quotient-field ((ring rational-integers))
(get-rational-numbers))
(defmethod make-quotient-element ((qf rational-numbers) numerator denominator)
(make-instance 'rational-number :domain qf :numerator numerator :denominator denominator))
(defmethod print-object ((ratfun rational-number) stream)
(with-numerator-and-denominator (numerator denominator) ratfun
(cond ((1? denominator)
(prin1 numerator stream))
(t (prin1 numerator stream)
(princ "/" stream)
(prin1 denominator stream)))))
(defmethod numerator ((r rational-number))
(qo-numerator r))
(defmethod denominator ((r rational-number))
(qo-denominator r))
(defmethod > ((x rational-number) (y rational-number))
(> (* (qo-numerator x) (qo-denominator y))
(* (qo-numerator y) (qo-denominator x))))
(defmethod < ((x rational-number) (y rational-number))
(< (* (qo-numerator x) (qo-denominator y))
(* (qo-numerator y) (qo-denominator x))))
(defmethod abs ((x rational-number))
(make-instance 'rational-number
:domain (domain-of x)
:numerator (abs (qo-numerator x))
:denominator (qo-denominator x)))